#include "concurrentAlloc.h"

void alloc1() {
	std::vector<void*> v;
	for (int i = 0; i < 3; ++i) {
		v.push_back(concurrentAlloc(6));
	}

	for (auto& it : v) {
		concurrentFree(it);
	}
}

void alloc2() {
	std::vector<void*> v;
	for (int i = 0; i < 3; ++i) {
		v.push_back(concurrentAlloc(19));
	}

	for (auto& it : v) {
		concurrentFree(it);
	}
}

void galloc1() {
	std::vector<void*> v;
	for (int i = 0; i < 3; ++i) {
		v.push_back(concurrentAlloc(512 * 1024));
	}

	for (auto& it : v) {
		concurrentFree(it);
	}
}

void galloc2() {
	std::vector<void*> v;
	for (int i = 0; i < 3; ++i) {
		v.push_back(concurrentAlloc(512 * 4 * 1024));
	}

	for (auto& it : v) {
		concurrentFree(it);
	}
}

void tlsAlloc() {
	std::thread t1(alloc1), t2(alloc2);

	t1.join();
	t2.join();
}

void request() {
	std::vector<void*> v;
	v.push_back(concurrentAlloc(56));
	v.push_back(concurrentAlloc(69));
	v.push_back(concurrentAlloc(18));
	v.push_back(concurrentAlloc(28));
	v.push_back(concurrentAlloc(9));
	v.push_back(concurrentAlloc(6));
	v.push_back(concurrentAlloc(6));
	v.push_back(concurrentAlloc(6));
	v.push_back(concurrentAlloc(6));

	for (auto& it : v) {
		concurrentFree(it);
	}
}

void release() {
	std::thread t1(alloc1), t2(galloc2);

	t1.join();
	t2.join();
}

void greater() {
	std::vector<void*> v;
	v.push_back(concurrentAlloc(512 * 1024));
	v.push_back(concurrentAlloc(512 * 4 * 1024));

	for (auto& it : v) {
		concurrentFree(it);
	}
}

//int main() {
//	//srand(time(nullptr));
//	//TestPool();
//	//tlsAlloc();
//	//request();
//	//release();
//	greater();
//
//	return 0;
//}